<template>
  <div class="authentication">
    <div class="com-top-nav">
      <van-nav-bar
        title="偏好设置"
        left-arrow
        @click-left="onClickLeft"
      />
    </div>
    <div>
      <van-cell-group>
        <zx-picker title="可工作时间" :dataList="timeList" v-model="formData.time"></zx-picker>
        <zx-picker title="目前状态" :dataList="statusList" v-model="formData.status"></zx-picker>
        <zx-picker title="技能方向" :dataList="skillList" v-model="formData.skill"></zx-picker>
      </van-cell-group>
      <div class="button">
        <van-button size="large" @click="handleSubmit">保存</van-button>
      </div>

    </div>
  </div>
</template>
<script>
  import validator from '../../../common/validatorFunction';
  import zxPicker from '../../../components/zx-picker'

  export default {
    name:'preferences',
    components: {
      zxPicker
    },
    data(){
      return {
        isShowError: false,
        errorTips: '',
        timeList: [{values: ['周末', '工作日','其他']}],
        skillList: [{values: ['设计', '编程', '文案']}],
        statusList: [{values: ['在校', '在职', '其他']}],
        formData: {
          time: [],
          skill: [],
          status: []
        },
        rules: {
          time: [
            {require: true, message: '请输入姓名'}
          ],
          skill: [
            {require: true, message: '请填写学校名称'}
          ],
          status: [
            {require: true, message: '请输入您的自我评价'}
          ]
        }
      }
    },
    mounted() {
    // a
    },
    methods: {
      onClickLeft() {
        this.$router.go(-1);
      },
      handleSubmit() {
        // 保存数据
        const rulesResult = validator(this.formData, this.rules);
        console.log(rulesResult);
        if (rulesResult.result) {
          // 校验成功，保存信息
          // const res = await server.postIdData(this.formData);
          // if (res && res.data && res.data.code === 200) {
          //     this.$router.push('/information-data');
          // }
        } else {
          const alertMessage = [];
          for (const key in rulesResult.detail) {
            if (!rulesResult.detail[key].isPass) {
              alertMessage.push(rulesResult.detail[key].message);
            }
          }
          this.isShowError = true;
          this.errorTips = alertMessage[0];
          this.$toast({message:this.errorTips, position: 'middle'});
        }
      }
    }
  }
</script>

<style scoped lang="less" type="text/less">
  @import url('../../../../static/style/var');
  .button {
    padding-left: 10px;
    padding-right: 10px;
    margin-top: 30px;
  }
</style>
